USE [PatientManagement]
GO
/****** Object:  StoredProcedure [dbo].[DeletePrescriptionTemplate]    Script Date: 10/18/2013 22:36:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[DeletePrescription] 
	-- Add the parameters for the stored procedure here
	@prescriptionId		INT,
	@result      INT OUTPUT
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
 SET NOCOUNT ON

/*________________________ VALIDATE PARAMETERS _________________________*/


/*_______________________________ MAIN _________________________________*/
	
	SET @result = 1
													
	BEGIN TRAN DeletePrescription
	BEGIN TRY
		-- UPDATE BillDetail_InProdDetail, set null for related BillDetail_InProdDetail
		DELETE FROM dbo.PrescriptionDetails
		WHERE PrescriptionId = @prescriptionId	
		
		DELETE FROM dbo.Prescription
		WHERE Id = @prescriptionId
			
		SET @result = 1
		
		COMMIT TRANSACTION DeletePrescription
	END TRY
	BEGIN CATCH
		SET @result = 0
		PRINT 'Error'
	  ROLLBACK TRANSACTION DeletePrescription
	  
	END CATCH
END
